package com.aibaixun.web.controller.task;

import com.aibaixun.system.service.EvsApiService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author zhangyh
 * @date 2023-03-23
 **/
@Component
public class CommonTask {
    private static final Logger logger = LoggerFactory.getLogger(CommonTask.class);

    @Autowired
    private EvsApiService evsApiService;

    @Value("${commonConfig.isOut}")
    private Boolean isOut;

    /**
     * 每日清空人员布控名单库，每日凌晨执行
     */
    @Scheduled(cron ="0 0 0 * * ?")
    public void deleteThirdWorkerOrderUser() {
        System.out.println("清空人员布控名单库任务开始==========================");
        evsApiService.deleteThirdWorkerOrderUser();
        System.out.println("清空人员布控名单库任务结束==========================");
    }

    /**
     * 定时任务拉去AI事件信息，每分钟执行
     */
    @Scheduled(cron ="0 */1 * * * ?")
    public void getAiEventInfoData() {
        System.out.println("定时任务拉去AI事件信息任务开始==========================");
        if(!isOut){
            evsApiService.getAiEventInfoData();
        }
        System.out.println("定时任务拉去AI事件信息任务结束==========================");
    }

    /**
     * 定时任务监听Ai视频设备状态进行异常重试
     */
    @Scheduled(cron ="0 0 */2 * * ?")
    public void checkAiDeviceStatus() {
        System.out.println("定时任务监听Ai视频设备状态进行异常重试任务开始==========================");
        evsApiService.checkAiDeviceStatus();
        System.out.println("定时任务监听Ai视频设备状态进行异常重试任务结束==========================");
    }

    /**
     * 定时任监听获取机柜U信息更新数据库
     */
//    @Scheduled(cron = "0 0 4 * * ?")
    public void getSeatMessageData(){
        logger.info("定时任务更新机柜信息开始=====================");
        evsApiService.getSeatMessageData();
        logger.info("定时任务更新机柜信息结束=====================");
    }

    @Scheduled(cron = "0 0 0 * * ? ")
    public void getAssetsMessage(){
        logger.info("定时任务更新资产信息开始=====================");
        evsApiService.getAssetsMessage();
        logger.info("定时任务更新资产信息结束=====================");
    }


    /**
     * 同步没小时能效数据
     */
    @Scheduled(cron = "0 0 */2 * * ?")
    public void getEnergyEfficiency(){
        evsApiService.getEnergyEfficiency();
        logger.info("更新能效数据结束=====================");
    }

}
